package com.example.ice.fittime;

import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.example.ice.fittime.adapter.SocialRecyclerAdapter;
import com.example.ice.fittime.global.ClassType;
import com.example.ice.fittime.global.Constants;
import com.example.ice.fittime.util.NetUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SocialActTickerActivity extends AppCompatActivity implements View.OnClickListener, Callback<List> {

    private RecyclerView recycler;
    private Toolbar toolbar;
    RecyclerView.LayoutManager layoutManager;
    private SocialRecyclerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_social_act_ticker);
        toolbar = (Toolbar) findViewById(R.id.social_act_ticker_toolbar);

        recycler = (RecyclerView) findViewById(R.id.social_sticker_recycler);
        setSupportActionBar(toolbar);


        Intent intent = getIntent();
        String type = intent.getStringExtra("type");

        if (type.equals("hottopic")) {
            toolbar.setTitle("热门标签");
            layoutManager = new GridLayoutManager(this,2);
            NetUtil.getData(ClassType.Sticker,this);
        }

        if (type.equals("hotuser")){
            toolbar.setTitle("热门用户");
            layoutManager = new LinearLayoutManager(this);
            long time = new Date().getTime();
            NetUtil.getData(ClassType.HotUser,this,"hot-user",Long.toBinaryString(time),"15","0");
        }
        recycler.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
                super.onDraw(c, parent, state);
                c.drawColor(Color.WHITE);
            }

            @Override
            public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
                super.onDrawOver(c, parent, state);
            }

            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                super.getItemOffsets(outRect, view, parent, state);
                outRect.set(5,5,5,5);
            }
        });



        recycler.setLayoutManager(layoutManager);
        adapter = new SocialRecyclerAdapter(new ArrayList<>(), this, this);
        recycler.setAdapter(adapter);
        toolbar.setNavigationIcon(R.mipmap.sobot_icon_back_normal);
        toolbar.setNavigationOnClickListener(this);


    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void onFailure(Call call, Throwable t) {

    }



    @Override
    public void onResponse(Call<List> call, Response<List> response) {
        List body = response.body();
        adapter.addAll(body);
    }
}
